from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://www.wentian123.com/jiangxi/")
    with page.expect_popup() as page1_info:
        page.get_by_role("link", name="鄱阳").click()
    page1 = page1_info.value
    page1.get_by_placeholder("开始日期").fill("2023-02-27")
    page1.get_by_placeholder("结束日期").fill("2023-02-28")
    page1.locator("input[type=\"submit\"]").click()
    page1.locator("div").filter(has_text="首页 > 天气历史记录搜索 鄱阳县 从2023-02-27到2023-02-28 天气历史记录 江西省上饶市鄱阳县 星期二 2023-02-28 多云转阴 8℃").nth(1).click()
    page1.locator("div").filter(has_text="首页 > 天气历史记录搜索 鄱阳县 从2023-02-27到2023-02-28 天气历史记录 江西省上饶市鄱阳县 星期二 2023-02-28 多云转阴 8℃").nth(1).click()
    page1.get_by_role("cell", name="8℃ ～ 15℃").dblclick()
    page1.locator("div").filter(has_text="首页 > 天气历史记录搜索 鄱阳县 从2023-02-27到2023-02-28 天气历史记录 江西省上饶市鄱阳县 星期二 2023-02-28 多云转阴 8℃").nth(1).click()
    page1.locator("div").filter(has_text="查询").nth(2).click()
    page1.locator("div").filter(has_text="查询").nth(2).dblclick()
    page1.locator("div").filter(has_text="查询").nth(2).dblclick()
    page1.close()
    page.close()

    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)
